<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
</head>

<body>
    <h1>jquery的ajax</h1>
    <button id="btn">ajax请求</button>
</body>

</html>
<script>

    btn.onclick = function () {
       $.ajax({
            // type:"get",
            // type:"post",
            // type:"put",
            type:"delete",
            url:"http://localhost:3000",
            success(result){
                console.log(result);
            }
        })
        
    }

</script>
<!-- 
    ajax请求的地址：http://localhost:3000
    ajax所在的页面地址： 
    file:///C:\Users\IBM\Desktop\软件学院0906\day19jQuery的ajax和跨域\代码\跨域\index.html

    两个地址不是同一个服务器（协议、服务器地址、端口）（跨域，不同源）
    协议、服务器名称、端口三项只要有一项不同，那么就是跨域，三项一模样才是同源


    Access to XMLHttpRequest at 'http://localhost:3000/' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

    Access to XMLHttpRequest at 'http://localhost:3000/' from origin 'http://127.0.0.1:5500' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.


    Access to XMLHttpRequest at 'http://localhost:3000/' from origin 'http://127.0.0.1:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.


    在http://127.0.0.1:5500这个服务器上，通过ajax请求 http://localhost:3000/ 服务器的时候，被CORS（跨域资源共享）这个政策阻止：
    CORS规定，如果使用ajax请求跨域资源的时候，不能直接获取，必须设置响应头
    
 -->
 <!-- 
    Access to XMLHttpRequest at 'http://localhost:3000/' from origin 'null' has been blocked by CORS policy: Method PUT is not allowed by Access-Control-Allow-Methods in preflight response.
    put方法不被Access-Control-Allow-Methods允许

    ajax默认不支持put和delete（但是可以支持，需要设置Access-Control-Allow-Methods）

  -->
